package com.lagou.curator;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;

public class CreateNode {

    public static void main(String[] args) throws Exception {
        //不使用 fluent编程风格
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

        //使用 fluent编程风格
        CuratorFramework client = CuratorFrameworkFactory.builder()
                //zk的server地址，多个server之间使⽤英⽂逗号分隔开
                .connectString("127.0.0.1:2181")
                .sessionTimeoutMs(60 * 1000)
                .connectionTimeoutMs(15 * 1000)
                .retryPolicy(retryPolicy)
                //命名空间，每次操作都会在命名空间
                .namespace("base")
                .build();
        client.start();
        System.out.println("会话2创建成功。。。");

        String s = client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath("/lg_curator/c1/c11");
        System.out.println("节点：" + s + "创建成功");
    }

}
